--- Function to retrieve console output asynchronously.
--- --
--- @param cmd string command to execute
--- @param raw boolean flag to return result as default.
--- @return string # output given by the command.
function os.capture(cmd, raw) 
    local handle = assert(io.popen(cmd, 'r'))
    local output = assert(handle:read('*a'))

    handle:close()

    if raw then return output end

    output = string.gsub(string.gsub(string.gsub(output,'^%s+',''),'%s+$',''),
        '[\n\r]+',' ')
    return output
end

return {
    capture = os.capture
}
